package com.kingbook.services;

import com.kingbook.common.utils.StringUtils;
import com.kingbook.core.base.BaseService;
import com.kingbook.core.base.SupportService;
import com.kingbook.core.result.JSONPageResult;
import com.kingbook.core.result.JSONResult;
import com.kingbook.entity.Category;
import com.kingbook.enums.CategoryEnum;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author Bucky
 * @Date 2019-12-20 23:03:08
 * @Version 1.0
 */
@Slf4j
@Service
public class CategoryService extends SupportService {

    @PostConstruct
    private void init() {
        setNamespace("Category");
    }

    public void updateCategoryName(int mid, CategoryEnum category, String name) {
        if(StringUtils.isNotEmpty(name)) {
            Map<String, Object> param = Maps.newHashMap();
            param.put("mid", mid);
            param.put("category", category.name());
            param.put("name", name);
            if (getRows(param) == 0) {
                insert("insert", param);
            }
        }
    }


    public Map<String, Object>[] queryMap(CategoryEnum category) {
        Map<String, Object> param = new HashMap<>(2);
        param.put("mid", 0);
        param.put("category", category.name());
        return queryMap("query", param);
    }
}
